package com.fivefu.core.hik.controller;

import com.fivefu.base.common.utils.str.StrUtils;
import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hik.services.VideoNetWorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "视频网管")
@RestController
@RequestMapping("/hikVideoNetwork")
public class DbHikVideoNetworkController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(DbHikVideoNetworkController.class);

    @Resource
    private VideoNetWorkService videoNetWorkService;

    @ApiOperation(value = "根据监控点列表查询录像完整性结果",httpMethod = "POST",response = ResultInfo.class,notes = "根据监控点列表查询录像完整性结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "beginTime",value = "录像开始日期(采用ISO8601标准，如2020-09-23T15:37:27.256+08:00)",paramType = "query",required = true,dataType = "String"),
            @ApiImplicitParam(name = "endTime",value = "录像结束日期(采用ISO8601标准，如2020-09-23T15:37:27.256+08:00)",paramType = "query",required = true,dataType = "String")
    })
    @RequestMapping(path = "/queryVideoIntegrity",method = RequestMethod.POST)
    public ResultInfo queryVideoIntegrity(){
        try {
            logger.info("根据监控点列表查询录像完整性结果接收的参数为："+request.getParameterMap());
            String beginTime = StrUtils.isCheckNull(request.getParameter("beginTime"));
            String endTime = StrUtils.isCheckNull(request.getParameter("endTime"));
            if (StrUtils.isNull(beginTime)){
                return ResultInfo.renderError("录像开始日期不能为空");
            }
            if (StrUtils.isNull(endTime)){
                return ResultInfo.renderError("录像结束日期不能为空");
            }
            videoNetWorkService.queryVideoIntegrity(beginTime,endTime);
            return ResultInfo.renderSuccess("根据监控点列表查询录像完整性结果成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultInfo.renderError("根据监控点列表查询录像完整性结果失败");
    }

    @ApiOperation(value = "根据监控点列表查询视频质量诊断结果",httpMethod = "POST",response = ResultInfo.class,notes = "根据监控点列表查询视频质量诊断结果")
    @RequestMapping(path = "/queryVideoQuality",method = RequestMethod.POST)
    public ResultInfo queryVideoQuality(){
        try {
            videoNetWorkService.queryVideoQuality();
            return ResultInfo.renderSuccess("根据监控点列表查询视频质量诊断结果成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultInfo.renderError("根据监控点列表查询视频质量诊断结果失败");
    }

    @ApiOperation(value = "获取监控点在线状态",httpMethod = "POST",response = ResultInfo.class,notes = "获取监控点在线状态")
    @RequestMapping(path = "/queryOnlineCamera",method = RequestMethod.POST)
    public ResultInfo queryOnlineCamera(){
        try {
            videoNetWorkService.queryOnlineCamera();
            return ResultInfo.renderSuccess("获取监控点在线状态成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultInfo.renderError("获取监控点在线状态失败");
    }

    @ApiOperation(value = "获取编码设备在线状态",httpMethod = "POST",response = ResultInfo.class,notes = "获取编码设备在线状态")
    @RequestMapping(path = "/queryOnlineEncodeDevice",method = RequestMethod.POST)
    public ResultInfo queryOnlineEncodeDevice(){
        try {
            videoNetWorkService.queryOnlineEncodeDevice();
            return ResultInfo.renderSuccess("获取编码设备在线状态成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResultInfo.renderError("获取编码设备在线状态失败");
    }
}
